﻿using Foundation;
using UIKit;
using System;
using UMessageTouch;
using UMAnalytics;
using UmengSocial;

namespace UMengTouchDemo
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the
    // User Interface of the application, as well as listening (and optionally responding) to application events from iOS.
    [Register("AppDelegate")]
    public class AppDelegate : UIApplicationDelegate
    {
        // class-level declarations

        public override UIWindow Window
        {
            get;
            set;
        }

        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            // Code to start the Xamarin Test Cloud Agent
//            MobClick.StartWithAppkey("55b8446f67e58e56850059ff");
//
//            UMessage.SetLogEnabled(true);
//            UMessage.StartWithAppkey("55b8446f67e58e56850059ff", launchOptions);
//
//            UIMutableUserNotificationAction a1 = new UIMutableUserNotificationAction();
//            a1.Identifier = "action1_identifier";
//            a1.Title = "Accept";
//            a1.ActivationMode = UIUserNotificationActivationMode.Foreground;
//
//
//            UIMutableUserNotificationAction a2 = new UIMutableUserNotificationAction();
//            a2.Identifier = "action2_identifier";
//            a2.Title = "Reject";
//            a2.ActivationMode = UIUserNotificationActivationMode.Background;
//            a2.AuthenticationRequired = true;
//            a2.Destructive = true;
//
//            UIMutableUserNotificationCategory c = new UIMutableUserNotificationCategory();
//            c.Identifier = "category1";
//            c.SetActions(new []{ a1, a2 }, UIUserNotificationActionContext.Default);
//
//
//
//            var s = UIUserNotificationSettings.GetSettingsForTypes(
//                        UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
//                        new NSSet(c));
//            UMessage.RegisterRemoteNotificationAndUserNotificationSettings(s);
//            UMessage.AddTag(new NSString(@"Tag1"), (_, __, ___) =>
//                {
//                    Console.WriteLine("A");
//                });
        
            return true;
        }


        public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        {
            return UMSocialSnsService.HandleOpenURL(url);
        }


        public override void OnResignActivation(UIApplication application)
        {
            // Invoked when the application is about to move from active to inactive state.
            // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 
            // or when the user quits the application and it begins the transition to the background state.
            // Games should use this method to pause the game.
        }

        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Console.WriteLine(deviceToken.Description);
            UMessage.RegisterDeviceToken(deviceToken);
        }

        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            UMessage.DidReceiveRemoteNotification(userInfo);
        }

        public override void DidEnterBackground(UIApplication application)
        {
            // Use this method to release shared resources, save user data, invalidate timers and store the application state.
            // If your application supports background exection this method is called instead of WillTerminate when the user quits.
        }

        public override void WillEnterForeground(UIApplication application)
        {
            // Called as part of the transiton from background to active state.
            // Here you can undo many of the changes made on entering the background.
        }

        public override void OnActivated(UIApplication application)
        {
            // Restart any tasks that were paused (or not yet started) while the application was inactive. 
            // If the application was previously in the background, optionally refresh the user interface.
        }

        public override void WillTerminate(UIApplication application)
        {
            // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
        }
    }
}


